#include<stdio.h>
#include<stdlib.h>

typedef struct NODE
{
	struct NODE *p;//父节点
	struct NODE *l;//左子树
	struct NODE *r;//右子树
	int key;
} Node;


void Insert(Node *tree,Node *node)
{
	while(tree->p!=NULL)	tree=tree->p;
	while(node->p!=NULL)	node=node->p;
	//寻找祖先
	if(tree==node) return;
	node->p=tree;
	Node *root=tree;//令root为tree
	while(1)
	{
		if(node->key<root->key)
		{
			if(root->l==NULL)
			{
				root->l=node;
				return;
			}
			root=root->l;
		}
		else
		{
			if(root->r==NULL)
			{
				root->r=node;
				return;
			}
			root=root->r;
		}
	}
}

int Find(Node *tree,Node *node)
{
	while(tree->p!=NULL) tree=tree->p;
	while(node->p!=NULL) node=node->p;
	if(tree==node) return 1;//表明在此树中
	return 0;
}//在某个树中寻找另外一个节点，原理是寻找两个节点的祖先是否一致
